/**
 * 智慧小区管理系统 - 类型定义
 * @author Wu.Liang
 * @date 2024-01-01
 */

// 通用响应结构
export interface ApiResponse<T = unknown> {
    code: number
    message: string
    data: T
    success: boolean
    timestamp: number
}

// 分页参数
export interface PageParams {
    page: number
    size: number
    [key: string]: unknown
}

// 分页结果
export interface PageResult<T = unknown> {
    records: T[]
    total: number
    current: number
    size: number
    pages: number
}

// 用户信息
export interface UserInfo {
    id: string
    username: string
    nickname: string
    avatar?: string
    email?: string
    phone?: string
    role: string
    permissions: string[]
    communityId?: string
    communityName?: string
    propertyCompanyId?: number | string
    propertyCompanyName?: string
    propertyCompanyCode?: string
    status: number
    createTime: string
    updateTime: string
}

// 菜单信息
export interface MenuInfo {
    id: string
    name: string
    path: string
    component?: string
    icon?: string
    parentId?: string
    orderNum: number
    menuType: 'M' | 'C' | 'F' // M目录 C菜单 F按钮
    visible: boolean
    status: number
    permissions?: string
    children?: MenuInfo[]
}

// 表格列配置
export interface TableColumn {
    key: string
    title: string
    dataIndex: string
    width?: number
    fixed?: 'left' | 'right'
    sortable?: boolean
    searchable?: boolean
    render?: (value: unknown, record: unknown, index: number) => unknown
}

// 表单项配置
export interface FormItem {
    name: string
    label: string
    type: 'input' | 'select' | 'date' | 'textarea' | 'upload' | 'switch' | 'radio' | 'checkbox'
    required?: boolean
    placeholder?: string
    options?: { label: string; value: unknown }[]
    rules?: unknown[]
    props?: Record<string, unknown>
}

// 字典数据
export interface DictData {
    dictCode: string
    dictValue: string
    dictLabel: string
    dictType: string
    cssClass?: string
    listClass?: string
    isDefault: boolean
    status: number
    remark?: string
}

// 文件信息
export interface FileInfo {
    uid: string
    name: string
    url: string
    size: number
    type: string
    status: 'uploading' | 'done' | 'error'
}

// 社区信息
export interface CommunityInfo {
    id: string
    name: string
    address: string
    description?: string
    manager: string
    phone: string
    email?: string
    status: number
    createTime: string
    updateTime: string
}

// 住户信息
export interface ResidentInfo {
    id: string
    name: string
    phone: string
    idCard: string
    avatar?: string
    communityId: string
    buildingId: string
    roomNumber: string
    memberType: 'owner' | 'tenant' | 'family' // 业主、租客、家属
    status: number
    createTime: string
    updateTime: string
}

// 物业服务
export interface PropertyService {
    id: string
    title: string
    description: string
    category: string
    price?: number
    duration?: string
    status: number
    createTime: string
    updateTime: string
}

// 停车位信息
export interface ParkingSpace {
    id: string
    spaceNumber: string
    spaceType: 'fixed' | 'temporary' // 固定、临时
    status: 'available' | 'occupied' | 'reserved' // 可用、占用、预约
    buildingId: string
    floor?: number
    area?: number
    price?: number
    ownerId?: string
    createTime: string
    updateTime: string
}

// 设备信息
export interface DeviceInfo {
    id: string
    name: string
    code: string
    type: string
    brand?: string
    model?: string
    location: string
    status: 'online' | 'offline' | 'maintenance' // 在线、离线、维护
    installTime?: string
    lastCheckTime?: string
    createTime: string
    updateTime: string
}

// 通知公告
export interface NotificationInfo {
    id: string
    title: string
    content: string
    type: 'notice' | 'announcement' | 'emergency' // 通知、公告、紧急
    priority: 'low' | 'normal' | 'high' | 'urgent' // 优先级
    publisherId: string
    publisherName: string
    publishTime: string
    expireTime?: string
    status: number
    readCount: number
    isRead?: boolean
}

// 投诉建议
export interface ComplaintInfo {
    id: string
    title: string
    content: string
    category: string
    priority: 'low' | 'normal' | 'high'
    status: 'pending' | 'processing' | 'resolved' | 'closed' // 待处理、处理中、已解决、已关闭
    submitterId: string
    submitterName: string
    handlerId?: string
    handlerName?: string
    submitTime: string
    handleTime?: string
    resolveTime?: string
    images?: string[]
    feedback?: string
}

// 预约信息
export interface AppointmentInfo {
    id: string
    serviceId: string
    serviceName: string
    userId: string
    userName: string
    phone: string
    appointmentTime: string
    duration: number
    description?: string
    status: 'pending' | 'confirmed' | 'completed' | 'cancelled' // 待确认、已确认、已完成、已取消
    createTime: string
    updateTime: string
}

// 支付信息
export interface PaymentInfo {
    id: string
    orderNo: string
    title: string
    amount: number
    payType: 'wechat' | 'alipay' | 'bank' | 'cash' // 支付方式
    status: 'pending' | 'paid' | 'failed' | 'refunded' // 待支付、已支付、支付失败、已退款
    userId: string
    userName: string
    payTime?: string
    refundTime?: string
    remark?: string
    createTime: string
    updateTime: string
}

// 组件Props类型
export interface ComponentProps {
    [key: string]: unknown
}

// 路由信息
export interface RouteInfo {
    path: string
    name: string
    component: unknown
    meta?: {
        title?: string
        icon?: string
        hidden?: boolean
        requireAuth?: boolean
        permissions?: string[]
        keepAlive?: boolean
    }
    children?: RouteInfo[]
}

// 主题配置
export interface ThemeConfig {
    primaryColor: string
    isDark: boolean
    sidebarCollapsed: boolean
    layout: 'vertical' | 'horizontal'
    fixedHeader: boolean
    showTabs: boolean
    showBreadcrumb: boolean
}

// 应用配置
export interface AppConfig {
    title: string
    version: string
    description: string
    logo: string
    apiBaseUrl: string
    uploadUrl: string
    wsUrl: string
    enableMock: boolean
    enableDevtools: boolean
}

// 登录请求接口
export interface LoginRequest {
    username: string
    password: string
    captcha?: string
    rememberMe?: boolean
}

// 登录响应接口
export interface LoginResponse {
    token: string
    refreshToken: string
    userInfo: UserInfo
}

// 用户权限信息响应
export interface UserAuthInfo {
    userInfo: UserInfo
    roles: string[]
    permissions: string[]
    routes: unknown[]
}

// 菜单/路由接口
export interface MenuRoute {
    id: number
    path: string
    name: string
    component?: string
    redirect?: string
    meta: {
        title: string
        icon?: string
        hidden?: boolean
        keepAlive?: boolean
        permission?: string
        roles?: string[]
    }
    children?: MenuRoute[]
}
